package com.example.myzhugezhaofang.activity;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.mvplibrary.ui.activity.BaseActivity;
import com.example.myzhugezhaofang.R;
import com.example.myzhugezhaofang.adapter.FragTabAdapter;
import com.example.myzhugezhaofang.fragment.ConsultingFragment;
import com.example.myzhugezhaofang.fragment.HomeFragment;
import com.example.myzhugezhaofang.fragment.MessageFragment;
import com.example.myzhugezhaofang.fragment.MyFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

import butterknife.BindView;

public class MainActivity extends BaseActivity {
    @BindView(R.id.tab_main)
    TabLayout tab_main;
    @BindView(R.id.vp_main)
    ViewPager viewPager;
    private HomeFragment homeFragment;
    private MessageFragment messageFragment;
    private ConsultingFragment consultingFragment;
    private MyFragment myFragment;

    @Override
    protected void initData() {
        homeFragment = new HomeFragment();
        messageFragment = new MessageFragment();
        consultingFragment = new ConsultingFragment();
        myFragment = new MyFragment();
        ArrayList<String> list = new ArrayList<>();
        list.add("首页");
        list.add("消息");
        list.add("资讯");
        list.add("我");
        ArrayList<Integer> icon = new ArrayList<>();
        ArrayList<Fragment> fragments = new ArrayList<>();
        icon.add(R.drawable.home_select_icon);
        icon.add(R.drawable.message_select_icon);
        icon.add(R.drawable.consulting_select_icon);
        icon.add(R.drawable.my_select_icon);
        fragments.add(homeFragment);
        fragments.add(messageFragment);
        fragments.add(consultingFragment);
        fragments.add(myFragment);

        FragTabAdapter fragTabAdapter = new FragTabAdapter(getSupportFragmentManager(), fragments, list);
        viewPager.setAdapter(fragTabAdapter);
        tab_main.setupWithViewPager(viewPager);
        for (int i = 0; i < 4; i++) {
            tab_main.getTabAt(i).setIcon(icon.get(i));
        }
    }

    @Override
    protected int createLayoutId() {
        return R.layout.activity_main;
    }
}